import { reqLogin } from '@/api/user'
export default {
  namespaced: true,
  state: {
    name: '',
    token: '',
  },
  actions: {
    // 登录
    async reqLogin({ commit }, { phone, password }) {
      // 发送请求获取用户数据
      const user = await reqLogin(phone, password)
      // console.log(user)
      commit('LOGIN', user)
    },
  },
  mutations: {
    LOGIN(state, user) {
      // 将获取到的token存到localstore中
      localStorage.setItem('name', user.name)
      localStorage.setItem('token', user.token)
      // 存到vuex中
      state.name = user.name
      state.token = user.token
    },
  },
}
